package com.pc.ssm.service.impl;

import com.pc.ssm.dao.PageTemplateDao;
import com.pc.ssm.dao.PageTemplateMapper;
import com.pc.ssm.pojo.PageTemplate;
import com.pc.ssm.pojo.PageTemplateDetail;
import com.pc.ssm.pojo.PageTemplateExample;
import com.pc.ssm.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*******************************************************************************************
 * 类描述：  
 *
 * @author: dustin
 * @date: 2017-11-22 22:31
 * @Description:
 * @version 1.0
 *
 *
 * Version    Date       ModifiedBy                 Content  
 * -------- ---------    ----------         -----------------
 @Service-------
 * 1.0      2017/11/22     dst                               
 *******************************************************************************************
 */
@Service
public class TemplateServiceImpl implements TemplateService {
    // 注入用户Mapper
    @Autowired
    private PageTemplateMapper pageTemplateMapper;
    @Resource
    private PageTemplateDao pageTemplateDao;

    @Override
    public List<PageTemplate> findAllTemplate() {
        PageTemplateDetail pageTemplateDetail= pageTemplateDao.getTemplateDetail(150410402162941L);

        PageTemplateExample pageTemplateExample=new PageTemplateExample();
        PageTemplateExample.Criteria criteria=pageTemplateExample.createCriteria();
        criteria.andTemplatetypeEqualTo(1);
        List<PageTemplate> templates=pageTemplateMapper.selectByExample(pageTemplateExample);


        return pageTemplateMapper.selectByExample(null);
    }

    @Override
    public PageTemplate findById(Long id) {
        return pageTemplateMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(PageTemplate pageTemplate) {
        if (pageTemplateMapper.updateByPrimaryKeySelective(pageTemplate) != 1) {
            throw new IncorrectUpdateSemanticsDataAccessException("更新异常");
        }
    }
}
